<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./template.xhtml"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://xmlns.jcp.org/jsf/core">

    <ui:define name="content">
        <h:outputStylesheet library="css" name="acesso.css" />
        <h:outputScript library="script" name="script.js" />
        <h:form id="frmAgenda">
            <p:growl id="msg1" />
            <p:panel header="Cadastro de Contato">
                <h:panelGrid columns="2">
                    <h:outputLabel />
                    <h:inputHidden value="#{bAgenda.agenda.id}" />
                    <h:outputLabel value="Nome.:" styleClass="lbt" />
                    <p:inputText value="#{bAgenda.agenda.nome}" styleClass="texto" onkeyup="this.value = this.value.toUpperCase()" required="true" requiredMessage="Campo nome não pode ser vazio" />
                    <h:outputLabel value="Telefone.:" styleClass="lbt" />
                    <p:inputMask value="#{bAgenda.agenda.foneFixo}" mask="(99)9999-9999" styleClass="texto" />
                    <h:outputLabel value="Celular.:" styleClass="lbt" />
                    <p:inputMask value="#{bAgenda.agenda.celular}" mask="(99)9999-9999" styleClass="texto" />
                    <h:outputLabel value="Email.:" styleClass="lbt" />
                    <p:inputText value="#{bAgenda.agenda.email}" styleClass="texto" onkeyup="this.value = this.value.toLowerCase()"/>
                </h:panelGrid>
                <h:panelGroup>
                    <h:commandButton value="Salvar" action="#{bAgenda.gravar}">
                        <p:ajax  event="keyup" update="@form"/>
                    </h:commandButton>
                    <h:commandButton value="Limpar" action="#{bAgenda.limpar}" />
                </h:panelGroup>
            </p:panel>
            
            <p:fieldset legend="Pesquisar">
                <h:panelGrid columns="2">
                    <h:outputLabel value="Nome.:" styleClass="lbt" />
                    <p:inputText value="#{bAgenda.nome}" styleClass="texto" onkeyup="this.value = this.value.toUpperCase()">
                        <p:ajax event="keyup" update=":frmTable" listener="#{bAgenda.pesquisar}" />
                    </p:inputText>
                </h:panelGrid>
            </p:fieldset>
        </h:form>
        <h:form id="frmTable">
            <p:dataTable value="#{bAgenda.agendas}" var="a">
                <p:column headerText="Nome">
                    <p:outputLabel value="#{a.nome}" />
                </p:column>
                <p:column headerText="Telefone" width="100">
                    <p:outputLabel value="#{a.foneFixo}" />
                </p:column>
                <p:column headerText="Celular" width="100">
                    <p:outputLabel value="#{a.celular}" />
                </p:column>
                <p:column headerText="Email" width="300">
                    <p:outputLabel value="#{a.email}" />
                </p:column>
                <p:column headerText="Op" width="100" style="text-align: center">
                    <h:commandLink value="Alterar" action="#{bAgenda.alterar(a.id)}" /> |
                    <h:commandLink value="Excluir" action="#{bAgenda.excluir(a.id)}" onclick="return confirmaExclusao();" />
                </p:column>
            </p:dataTable>
        </h:form>

    </ui:define>

</ui:composition>
